<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/templates/ui.xhtml">
<ui:define name="head">
    <script type="text/javascript" src="#{request.contextPath}/UI/support/pub.js"/>
    <script type="text/javascript" language="javascript">
        document.onkeydown = function TabReplace() {
            if (event.keyCode == 13) {
                if (event.srcElement.tagName != 'BUTTON')
                    event.keyCode = 9;
                else
                    event.srcElement.click();
            }
        }
    </script>
    <style type="text/css">
        .cancel_c {
            color: #ff0000;
        }
    </style>
</ui:define>
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data">
<p:growl id="msgs" showDetail="true"/>
<p:focus for="id"/>
<p:panel id="ppCondition" style="width: 100%">
    <h:panelGrid columns="2" style="width: 100%">
        <h:panelGrid id="pgCust" widgetVar="WvCust" columns="4" style="text-align: right;">
            <h:outputLabel value="纳税人识别号:" for="id" style="font-weight: bold"/>
            <p:inputText id="id" value="#{contractAction.queryCondition.taxerID}"/>

            <h:outputLabel value="纳税人名称:" for="name" style="font-weight: bold;margin-left: 100px;"/>
            <p:inputText id="name" value="#{contractAction.queryCondition.taxerName}"/>

            <h:outputLabel value="所属日期起:" for="startDate" style="font-weight: bold"/>
            <p:inputText id="startDate" value="#{contractAction.queryCondition.dateStart}"
                         onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>

            <h:outputLabel value="所属日期止:" for="endDate" style="font-weight: bold"/>
            <p:inputText id="endDate" value="#{contractAction.queryCondition.dateEnd}"
                         onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>

            <h:outputLabel value="所属税务机关:" for="taxOrgan" style="font-weight: bold"/>
            <p:inputText id="taxOrgan" value="#{contractAction.queryCondition.taxAuthority}"/>

            <h:outputLabel value="主管税务管员:" for="taxManager" style="font-weight: bold"/>
            <p:inputText id="taxManager" value="#{contractAction.queryCondition.taxManager}"/>

            <h:outputLabel value="合同类型:" for="contractType" style="font-weight: bold"/>
            <p:selectOneMenu id="contractType" value="#{contractAction.queryCondition.contractType}"
                             style="width: 145px;">
                <f:selectItem itemLabel="" itemValue=""/>
                <f:selectItem itemLabel="销售合同" itemValue="0044"/>
                <f:selectItem itemLabel="出租合同" itemValue="0045"/>
                <f:selectItem itemLabel="规划设计合同" itemValue="0042"/>
                <f:selectItem itemLabel="施工建设合同" itemValue="0043"/>
                <f:selectItem itemLabel="购买土地合同" itemValue="0041"/>
                <f:selectItem itemLabel="其它合同" itemValue="0046"/>
            </p:selectOneMenu>

            <h:outputLabel value="显示作废合同:" for="isShow" style="font-weight: bold"/>
            <p:selectOneMenu id="isShow" value="#{contractAction.queryCondition.canceled}" style="width: 145px;">
                <f:selectItem itemLabel="" itemValue=""/>
                <f:selectItem itemLabel="是" itemValue="是"/>
                <f:selectItem itemLabel="否" itemValue="否"/>
            </p:selectOneMenu>

        </h:panelGrid>
        <h:panelGrid style="width:10%">
            <p:commandButton id="qryBtn" value="查 询" actionListener="#{contractAction.query()}"
                             style="font-size: 14px;width: 80px;" update="tabSum,msgs">
            </p:commandButton>
            <p:commandButton id="resetBtn" type="reset" value="重 置"
                             style="font-size: 14px;width: 80px;">
            </p:commandButton>
        </h:panelGrid>
    </h:panelGrid>
</p:panel>
<p:ajaxStatus style="width:16px;height:16px;">
    <f:facet name="start">
        <h:graphicImage value="/images/ajaxloading.gif"/>
    </f:facet>
    <f:facet name="complete">
        <h:outputText value=""/>
    </f:facet>
</p:ajaxStatus>
<p:dataTable id="tabSum" style="width:100%;"
             value="#{contractAction.contractInfos}"
             var="contractInfo"
             rowKey="#{contractInfo.pkid}"
             selectionMode="single"
             selection="#{contractAction.contractInfoSelected}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true"
             paginatorPosition="bottom"
             rows="15"
             rowsPerPageTemplate="100,50,30,15"
             emptyMessage="数据记录为空..."
             widgetVar="tabSumVar">

    <p:ajax event="rowSelect"
            listener="#{contractAction.updateContractInfo(contractAction.queryCondition.canceled)}"
            update=":form:tabDetail"/>

    <p:column style="text-align:center" sortBy="#{contractInfo.NSRSBH}">
        <f:facet name="header">
            <h:outputText value="纳税人识别号"/>
        </f:facet>
        <h:outputText value="#{contractInfo.NSRSBH}"/>
    </p:column>

    <p:column style="text-align:center" filterBy="#{contractInfo.NSRMC}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="纳税人名称"/>
        </f:facet>
        <h:outputText value="#{contractInfo.NSRMC}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{contractInfo.contractType}">
        <f:facet name="header">
            <h:outputText value="合同类型"/>
        </f:facet>
        <h:outputText value="#{contractInfo.contractType}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{contractInfo.COUNT}">
        <f:facet name="header">
            <h:outputText value="份数"/>
        </f:facet>
        <h:outputText value="#{contractInfo.COUNT}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{contractInfo.AREA}">
        <f:facet name="header">
            <h:outputText value="面积"/>
        </f:facet>
        <h:outputText value="#{contractInfo.AREA}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{contractInfo.price}">
        <f:facet name="header">
            <h:outputText value="金额"/>
        </f:facet>
        <h:outputText value="#{contractInfo.price}">
            <f:convertNumber pattern="##################.##"/>
        </h:outputText>
    </p:column>

    <p:column style="text-align:center" filterBy="#{contractInfo.taxAuthority}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="税务机关"/>
        </f:facet>
        <h:outputText value="#{contractInfo.taxAuthority}"/>
        <f:facet name="footer">
            <h:outputText value="笔数：#{fn:length(contractAction.contractInfos)}"/>
        </f:facet>
    </p:column>

    <p:column style="text-align:center" filterBy="#{contractInfo.taxerManager}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="税管员"/>
        </f:facet>
        <h:outputText value="#{contractInfo.taxerManager}"/>
        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="tabSum" fileName="contractInfoSummary"/>
            </h:commandLink>
        </f:facet>
    </p:column>
</p:dataTable>
<br/>
<p:contextMenu for="tabDetail" id="pcm">
    <p:menuitem value="合同详情" icon="ui-icon-arrowrefresh-1-w" actionListener="#{contractAction.updateThContractFb()}"
                oncomplete="contractDetail.show()"
                update=":form:contractDetailTab"/>
    <p:menuitem id="cancelMenuId" value="作废原因" icon="ui-icon-arrowrefresh-1-w"
                oncomplete="canceledWhy.show()" actionListener="#{contractAction.findCanceledReason()}"
                update=":form:errorText"/>
</p:contextMenu>
<p:separator/>
<p:dataTable id="tabDetail" style="width:100%;"
             value="#{contractAction.thContracts}"
             var="thContract"
             rowKey="#{thContract.contractId}"
             selectionMode="single"
             selection="#{contractAction.thContractSelected}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true"
             paginatorPosition="bottom"
             rows="15"
             rowsPerPageTemplate="100,50,30,15,5"
             emptyMessage="数据记录为空..."
             widgetVar="tabDetailVar"
             rowStyleClass="#{contractAction.getRowStyleClass(thContract.contractId) ? 'cancel_c' : ''}">

    <f:facet name="header">
        <h:outputText value="合同详细信息"/>
    </f:facet>

    <p:column style="text-align:center" sortBy="#{thContract.contractId}">
        <f:facet name="header">
            <h:outputText value="合同编号"/>
        </f:facet>
        <h:outputText value="#{thContract.contractId}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="合同类型"/>
        </f:facet>
        <h:outputText value="#{thContract.contractType}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="卖方证件号"/>
        </f:facet>
        <h:outputText value="#{thContract.sellerId}"/>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="卖方名称"/>
        </f:facet>
        <h:outputText value="#{thContract.sellerTitle}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="买方证件号"/>
        </f:facet>
        <h:outputText value="#{thContract.buyerId}"/>
    </p:column>
    <p:column style="text-align:center" filterBy="#{thContract.buyerTitle}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="买方名称"/>
        </f:facet>
        <h:outputText value="#{thContract.buyerTitle}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="转让方式"/>
        </f:facet>
        <h:outputText value="#{thContract.transWay}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="房产地址"/>
        </f:facet>
        <h:outputText value="#{thContract.assetLoc}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thContract.assetArea}">
        <f:facet name="header">
            <h:outputText value="总面积"/>
        </f:facet>
        <h:outputText value="#{thContract.assetArea}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="付款次数"/>
        </f:facet>
        <h:outputText value="#{thContract.assetCount}"/>
    </p:column>
    <p:column style="text-align:center" sortBy="#{thContract.costAmount}">
        <f:facet name="header">
            <h:outputText value="总金额"/>
        </f:facet>
        <h:outputText value="#{thContract.costAmount}">
            <f:convertNumber pattern="##################.##"/>
        </h:outputText>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="付款方式"/>
        </f:facet>
        <h:outputText value="#{thContract.payWay}"/>
    </p:column>
    <p:column style="text-align:center" sortBy="#{thContract.inputDate}">
        <f:facet name="header">
            <h:outputText value="录入日期"/>
        </f:facet>
        <h:outputText value="#{thContract.inputDate}">
            <f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" locale="cn"></f:convertDateTime>
        </h:outputText>
        <f:facet name="footer">
            <h:outputText value="笔数：#{fn:length(contractAction.thContracts)}"/>
        </f:facet>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="备注"/>
        </f:facet>
        <h:outputText value="#{thContract.notes}"/>
        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="tabDetail" fileName="contractInfoDetail"/>
            </h:commandLink>
        </f:facet>
    </p:column>
</p:dataTable>
<p:dialog id="contractDetail" widgetVar="contractDetail" header="合同详情" modal="true" showEffect="drop"
          hideEffect="drop" width="650">
    <p:dataTable id="contractDetailTab"
                 value="#{contractAction.thContractfbList}"
                 var="thContractfb"
                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 paginator="true"
                 paginatorPosition="bottom"
                 rows="15"
                 rowsPerPageTemplate="100,50,30,15,5"
                 emptyMessage="数据记录为空...">

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="财产编号"/>
            </f:facet>
            <h:outputText value="#{thContractfb.assetId}"/>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="面积"/>
            </f:facet>
            <h:outputText value="#{thContractfb.assetArea}"/>
        </p:column>

        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="金额"/>
            </f:facet>
            <h:outputText value="#{thContractfb.costAmount}"/>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="单价"/>
            </f:facet>
            <h:outputText value="#{thContractfb.assetPrice}"/>
            <f:facet name="footer">
                <h:outputText value="笔数：#{fn:length(contractAction.thContractfbList)}"/>
            </f:facet>
        </p:column>
        <p:column style="text-align:center">
            <f:facet name="header">
                <h:outputText value="所处位置"/>
            </f:facet>
            <h:outputText value="#{thContractfb.assetLoc}"/>
            <f:facet name="footer">
                <h:commandLink>
                    <h:outputText value="[导出数据]"/>
                    <p:dataExporter type="xls" target="contractDetailTab" fileName="contractDetail"/>
                </h:commandLink>
            </f:facet>
        </p:column>
    </p:dataTable>
</p:dialog>
<p:dialog id="canceledWhy" widgetVar="canceledWhy" header="作废原因" modal="true" showEffect="drop" hideEffect="drop"
          width="250">
    <h:inputTextarea id="errorText"
                     value="#{contractAction.contractCanceledReason == null ? '该合同未作废' : contractAction.contractCanceledReason}"
                     disabled="true"
                     style="width: 220px;">
    </h:inputTextarea>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>